package hust.ioic.oa.base;


import hust.ioic.oa.domain.Operator;
import hust.ioic.oa.service.DepartmentService;

import hust.ioic.oa.service.CommentService;
import hust.ioic.oa.service.RdfileService;

import hust.ioic.oa.service.KnowTypeService;

import hust.ioic.oa.service.FunctionService;

import hust.ioic.oa.service.OperatorService;

import hust.ioic.oa.service.TextService;

import hust.ioic.oa.service.RoleService;
import hust.ioic.oa.service.MessageQueneService;








import java.lang.reflect.ParameterizedType;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public abstract class BaseAction<T> extends ActionSupport implements
		ModelDriven<T> {


	protected T model;
	protected int pageNum = 1;
	protected int pageSize = 10;

	public BaseAction() {
		
		try {
			ParameterizedType pt = (ParameterizedType) this.getClass()
					.getGenericSuperclass();
			Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];
			model = clazz.newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public T getModel() {
		return this.model;
	}

	/**
	 * 获取当前登录用户
	 * 
	 * @return
	 */
	public Operator getCurrentOperator() {
		return (Operator) ActionContext.getContext().getSession()
				.get("operator");
	}

	/**
	 * 通过提供的hashcode，查询数据库中临时队列表中指定记录的执行状态
	 * 2s查询一次
	 * 状态码1，4，6，return false
	 * 状态码0，2，3 循环等待
	 * 状态码5，return true
	 * @param hashCode
	 * @throws InterruptedException 
	 */



	// ============================================
	// 加载业务数据库对应的service，

	@Resource
	protected OperatorService operatorService;

	@Resource
	protected RoleService roleService;

	@Resource
	protected DepartmentService departmentService;

	@Resource
	protected FunctionService functionService;
	@Resource
	protected KnowTypeService knowTypeService;

	@Resource
	protected CommentService commentService;

	@Resource
	protected RdfileService rdfileService;

	@Resource
	protected MessageQueneService messageQueneService;

	@Resource
	protected TextService textService;


	
	// =====================Getter and Setter==========================
	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
}
